package com.elinkway.infinitemovies.async;

import android.content.Context;

import com.elinkway.infinitemovies.bean.Episode;
import com.elinkway.infinitemovies.bean.PageInfoData;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.PageInfoParser;
import com.lvideo.http.bean.LVideoDataHull;

import java.util.ArrayList;

/**
 * 在播放页面请求分页数据的Task
 * @author zhangshuo
 *
 */
public class RequestVideoPageInfoTask extends MoviesHttpAsyncTask<PageInfoData> {

    private String site ="";
    private String aid  ="";
    private String setDataOrder = "";
   
    private int pageIndex = 1;
    private int pageSize = 100;
    private int videoPosition = 0;
    
    private ArrayList<Episode> episodes;
    
    private RequestResultListener<PageInfoData> mListener;
    
    public RequestVideoPageInfoTask(Context context) {
        super(context);
    }

    @Override
    public LVideoDataHull<PageInfoData> doInBackground() {
        return MoviesHttpApi.requestVideoList(new PageInfoParser(episodes, site,setDataOrder), site, aid,
                pageIndex, pageSize);
    }


    @Override
    public void onPostExecute(int updateId, PageInfoData result) {
        if(null != mListener){
            mListener.onRequestSuccess(updateId, result);
        }
    }

    @Override
    public boolean onPreExecute() {
        if(null != mListener){
            mListener.onPreRequest();
        }
        return super.onPreExecute();
    }
    
    @Override
    public void netNull() {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.netNull();
    }
    
    @Override
    public void netErr(int updateId, String errMsg) {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.netErr(updateId, errMsg);
    }
    
    @Override
    public void dataNull(int updateId, String errMsg) {
        if(null != mListener){
            mListener.onRequestFailed();
        }
        super.dataNull(updateId, errMsg);
    }


    public String getAid() {
        return aid;
    }

    public void setAid(String aid) {
        this.aid = aid;
    }

    public int getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(int pageIndex) {
        this.pageIndex = pageIndex;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public RequestResultListener<PageInfoData> getmListener() {
        return mListener;
    }

    public void setmListener(RequestResultListener<PageInfoData> mListener) {
        this.mListener = mListener;
    }

    public String getSite() {
        return site;
    }

    public void setSite(String site) {
        this.site = site;
    }

    public ArrayList<Episode> getEpisodes() {
        return episodes;
    }

    public void setEpisodes(ArrayList<Episode> episodes) {
        this.episodes = episodes;
    }
    public int getVideoPosition() {
        return videoPosition;
    }

    public void setVideoPosition(int videoPosition) {
        this.videoPosition = videoPosition;
    }
    
    public String getSetDataOrder() {
        return setDataOrder;
    }

    public void setSetDataOrder(String setDataOrder) {
        this.setDataOrder = setDataOrder;
    }

}
